<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class UserController extends Controller
{
    //添加方法
    /**
      * @date 2020/10/14
      * @author kjh
      * @description {添加一个数据}
    */
    public function add() {
      return view('user/add');
    }



    public function store(Request $request) {
      $this->validate($request,['title'=>'required']);
      $input = $request -> except('token');
      $input['password'] = md5($input['password']);
      $res = User::create($input);
      if($res){
        return redirect('user/index');
      }else {
        return back();        
      }
      dd($res);
    }

    //模板
    public function index() {
      $user = User::get();
      // return $user;
      return view('user.list', ['user'=> $user]);
    }

   
    //模板
    public function edit($id) {
      $user = User::find($id);
      $user = [$user];
      return view('user.edit', ['user'=> $user]);
    }


    //测试数据库是否连接成功
    public function select(Request $request) {
      $name = '<h1>1111</h1>';
      return view('user.test')->with('name',$name);
    }

    public function update(Request $request) {
      $name = $request->input('name');
      return $name;
    }


}
